/*

	T. A13 Heterogeneous Effects of SNED on Teacher Outcomes II, School-Level

*/



global replica_dir=	"<add path to your working directory>"
global data_dir=	"$replica_dir/data"
global output_dir=	"$replica_dir/output"


use "$data_dir/slvl_fin.dta", clear  



global depvars  "dropped newtea exp aep10" 
global indepvars "municip rural_rbd_tm1 gender_tm1 tit_educ_tm1 permanent_tm1 tea_admin_tm1 multsch_tm1 i.sned_yr i.hg"

				
/*----------------------------------------------------------------------------*/





/*------------------------------------------------------------------------------ 
	
	All
*/



foreach yvar of global depvars{
	
eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if abs(st_ind25) <= 1.5 & cut25<mean_cut25, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if abs(st_ind10) <= 1.5 & cut10<mean_cut10, vce(cluster rbd)

eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if abs(st_ind25) <= 1.5 & cut25>=mean_cut25, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if abs(st_ind10) <= 1.5 & cut10>=mean_cut10, vce(cluster rbd)

}	
 

/*------------------------------------------------------------------------------

	PV
	
*/				
	
	
foreach yvar of global depvars{
	
eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==0 & abs(st_ind25) <= 1.5 & cut25<mean_cut25_pv, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==0 & abs(st_ind10) <= 1.5 & cut10<mean_cut10_pv, vce(cluster rbd)

eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==0 & abs(st_ind25) <= 1.5 & cut25>=mean_cut25_pv, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==0 & abs(st_ind10) <= 1.5 & cut10>=mean_cut10_pv, vce(cluster rbd)

}				


/*------------------------------------------------------------------------------

	MV
	
*/		

foreach yvar of global depvars{
	
eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==1 & abs(st_ind25) <= 1.5  & cut25<mean_cut25_mv, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==1 & abs(st_ind10) <= 1.5  & cut10<mean_cut10_mv, vce(cluster rbd)

eststo: reg `yvar'_tp1 `yvar'_tm1  treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if municip==1 & abs(st_ind25) <= 1.5  & cut25>=mean_cut25_mv, vce(cluster rbd)
eststo: reg `yvar'_tp1 `yvar'_tm1  treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if municip==1 & abs(st_ind10) <= 1.5  & cut10>=mean_cut10_mv, vce(cluster rbd)

}				


			



/*----------------------------------------------------------------------------
	
	Multiple hypothesis testing
*/


rwolf2 ///	
	(reg dropped_tp1 	dropped_tm1 treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if 				abs(st_ind25) <= 1.5 & cut25<mean_cut25, 	vce(cluster rbd)) ///
	(reg dropped_tp1 	dropped_tm1 treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if 				abs(st_ind10) <= 1.5 & cut10<mean_cut10, 	vce(cluster rbd)) /// 
	(reg dropped_tp1 	dropped_tm1 treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if	 			abs(st_ind25) <= 1.5 & cut25>=mean_cut25, 	vce(cluster rbd)) ///
	(reg dropped_tp1 	dropped_tm1 treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if 				abs(st_ind10) <= 1.5 & cut10>=mean_cut10, 	vce(cluster rbd)) /// 
	(reg newtea_tp1		newtea_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if 				abs(st_ind25) <= 1.5 & cut25<mean_cut25, 	vce(cluster rbd)) ///
	(reg newtea_tp1 	newtea_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if 				abs(st_ind10) <= 1.5 & cut10<mean_cut10, 	vce(cluster rbd)) /// 
	(reg newtea_tp1 	newtea_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if 				abs(st_ind25) <= 1.5 & cut25>=mean_cut25, 	vce(cluster rbd)) ///
	(reg newtea_tp1 	newtea_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if 				abs(st_ind10) <= 1.5 & cut10>=mean_cut10, 	vce(cluster rbd)) /// 
	(reg exp_tp1 		exp_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if 				abs(st_ind25) <= 1.5 & cut25<mean_cut25, 	vce(cluster rbd)) ///
	(reg exp_tp1 		exp_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if 				abs(st_ind10) <= 1.5 & cut10<mean_cut10, 	vce(cluster rbd)) /// 
	(reg exp_tp1 		exp_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if 				abs(st_ind25) <= 1.5 & cut25>=mean_cut25, 	vce(cluster rbd)) ///
	(reg exp_tp1 		exp_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if 				abs(st_ind10) <= 1.5 & cut10>=mean_cut10, 	vce(cluster rbd)) /// 
	(reg aep10_tp1 		exp_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if 				abs(st_ind25) <= 1.5 & cut25<mean_cut25, 	vce(cluster rbd)) ///
	(reg aep10_tp1 		aep10_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if 				abs(st_ind10) <= 1.5 & cut10<mean_cut10, 	vce(cluster rbd)) /// 
	(reg aep10_tp1 		aep10_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if 				abs(st_ind25) <= 1.5 & cut25>=mean_cut25, 	vce(cluster rbd)) ///
	(reg aep10_tp1 		aep10_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if 				abs(st_ind10) <= 1.5 & cut10>=mean_cut10, 	vce(cluster rbd)) /// 
	(reg dropped_tp1 	dropped_tm1 treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if municip==0 & abs(st_ind25) <= 1.5 & cut25<mean_cut25_pv, 	vce(cluster rbd)) ///
	(reg dropped_tp1 	dropped_tm1 treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if municip==0 & abs(st_ind10) <= 1.5 & cut10<mean_cut10_pv, 	vce(cluster rbd)) /// 
	(reg dropped_tp1 	dropped_tm1 treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if municip==0 & abs(st_ind25) <= 1.5 & cut25>=mean_cut25_pv, 	vce(cluster rbd)) ///
	(reg dropped_tp1 	dropped_tm1 treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if municip==0 & abs(st_ind10) <= 1.5 & cut10>=mean_cut10_pv, 	vce(cluster rbd)) /// 
	(reg newtea_tp1 	newtea_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if municip==0 & abs(st_ind25) <= 1.5 & cut25<mean_cut25_pv, 	vce(cluster rbd)) ///
	(reg newtea_tp1 	newtea_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if municip==0 & abs(st_ind10) <= 1.5 & cut10<mean_cut10_pv, 	vce(cluster rbd)) /// 
	(reg newtea_tp1 	newtea_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if municip==0 & abs(st_ind25) <= 1.5 & cut25>=mean_cut25_pv, 	vce(cluster rbd)) ///
	(reg newtea_tp1 	newtea_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if municip==0 & abs(st_ind10) <= 1.5 & cut10>=mean_cut10_pv, 	vce(cluster rbd)) /// 
	(reg exp_tp1 		exp_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if municip==0 & abs(st_ind25) <= 1.5 & cut25<mean_cut25_pv, 	vce(cluster rbd)) ///
	(reg exp_tp1 		exp_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if municip==0 & abs(st_ind10) <= 1.5 & cut10<mean_cut10_pv, 	vce(cluster rbd)) /// 
	(reg exp_tp1 		exp_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if municip==0 & abs(st_ind25) <= 1.5 & cut25>=mean_cut25_pv, 	vce(cluster rbd)) ///
	(reg exp_tp1 		exp_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if municip==0 & abs(st_ind10) <= 1.5 & cut10>=mean_cut10_pv, 	vce(cluster rbd)) /// 
	(reg aep10_tp1 		aep10_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if municip==0 & abs(st_ind25) <= 1.5 & cut25<mean_cut25_pv, 	vce(cluster rbd)) ///
	(reg aep10_tp1 		aep10_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if municip==0 & abs(st_ind10) <= 1.5 & cut10<mean_cut10_pv, 	vce(cluster rbd)) /// 
	(reg aep10_tp1 		aep10_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars}  	if municip==0 & abs(st_ind25) <= 1.5 & cut25>=mean_cut25_pv, 	vce(cluster rbd)) ///
	(reg aep10_tp1 		aep10_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}  	if municip==0 & abs(st_ind10) <= 1.5 & cut10>=mean_cut10_pv, 	vce(cluster rbd)) /// 
	(reg dropped_tp1 	dropped_tm1 treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} 	if municip==1 & abs(st_ind25) <= 1.5 & cut25<mean_cut25_mv, 	vce(cluster rbd)) ///
	(reg dropped_tp1 	dropped_tm1 treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} 	if municip==1 & abs(st_ind10) <= 1.5 & cut10<mean_cut10_mv, 	vce(cluster rbd)) /// 
	(reg dropped_tp1 	dropped_tm1 treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} 	if municip==1 & abs(st_ind25) <= 1.5 & cut25>=mean_cut25_mv, 	vce(cluster rbd)) ///
	(reg dropped_tp1 	dropped_tm1 treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}	if municip==1 & abs(st_ind10) <= 1.5 & cut10>=mean_cut10_mv, 	vce(cluster rbd)) /// 
	(reg newtea_tp1 	newtea_tm1 treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} 	if municip==1 & abs(st_ind25) <= 1.5 & cut25<mean_cut25_mv, 	vce(cluster rbd)) ///
	(reg newtea_tp1 	newtea_tm1 treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars}	if municip==1 & abs(st_ind10) <= 1.5 & cut10<mean_cut10_mv, 	vce(cluster rbd)) /// 
	(reg newtea_tp1 	newtea_tm1 treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} 	if municip==1 & abs(st_ind25) <= 1.5 & cut25>=mean_cut25_mv, 	vce(cluster rbd)) ///
	(reg newtea_tp1 	newtea_tm1 treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} 	if municip==1 & abs(st_ind10) <= 1.5 & cut10>=mean_cut10_mv, 	vce(cluster rbd)) /// 
	(reg exp_tp1 		exp_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} 	if municip==1 & abs(st_ind25) <= 1.5 & cut25<mean_cut25_mv, 	vce(cluster rbd)) ///
	(reg exp_tp1 		exp_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} 	if municip==1 & abs(st_ind10) <= 1.5 & cut10<mean_cut10_mv, 	vce(cluster rbd)) /// 
	(reg exp_tp1 		exp_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} 	if municip==1 & abs(st_ind25) <= 1.5 & cut25>=mean_cut25_mv, 	vce(cluster rbd)) ///
	(reg exp_tp1 		exp_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} 	if municip==1 & abs(st_ind10) <= 1.5 & cut10>=mean_cut10_mv, 	vce(cluster rbd)) /// 
	(reg aep10_tp1 		aep10_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} 	if municip==1 & abs(st_ind25) <= 1.5 & cut25<mean_cut25_mv, 	vce(cluster rbd)) ///
	(reg aep10_tp1 		aep10_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} 	if municip==1 & abs(st_ind10) <= 1.5 & cut10<mean_cut10_mv, 	vce(cluster rbd)) /// 
	(reg aep10_tp1 		aep10_tm1 	treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} 	if municip==1 & abs(st_ind25) <= 1.5 & cut25>=mean_cut25_mv, 	vce(cluster rbd)) ///
	(reg aep10_tp1 		aep10_tm1 	treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} 	if municip==1 & abs(st_ind10) <= 1.5 & cut10>=mean_cut10_mv, 	vce(cluster rbd)) /// 
		, ///
	indepvars(	treat25, treat10, treat25, treat10, treat25, treat10, treat25, treat10,  treat25, treat10, treat25, treat10, treat25, treat10, treat25, treat10,  ///
				treat25, treat10, treat25, treat10, treat25, treat10, treat25, treat10,  treat25, treat10, treat25, treat10, treat25, treat10, treat25, treat10,  ///
				treat25, treat10, treat25, treat10, treat25, treat10, treat25, treat10,  treat25, treat10, treat25, treat10, treat25, treat10, treat25, treat10  /// 
												) seed(12011303)  cluster(rbd) strata(sned_yr) idcluster(newclusterid) usevalid reps(500) //holm
		
matrix RW=e(RW)				

matrix list RW

foreach v of numlist 1(1)48{ // each variable is a row in RW

scalar rw_pv=RW[`v',3]
scalar h_pv =RW[`v',4]
estadd scalar rw_pv : est`v'
estadd scalar h_pv :  est`v' 

}

*   

local sample="all"
esttab est1 est2 est3 est4 est5 est6 est7 est8 est9 est10 est11 est12 est13 est14 est15 est16 using "$output_dir/post_s_extval_`sample'.tex", tex nolines fragment label replace  collabels(none) nomtitles nonumbers star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3)) ) ///
keep(treat25 treat10) ///
stats(N r2  rw_pv , fmt(0 3 3 3)  ///
labels(`"Observations"' `"R-squared"' `"Romano-Wolf p-value"' ))

local sample="pv"
esttab est17 est18 est19 est20 est21 est22 est23 est24  est25 est26 est27 est28 est29 est30 est31 est32 using "$output_dir/post_s_extval_`sample'.tex", tex nolines fragment label replace  collabels(none) nomtitles nonumbers star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3)) ) ///
keep(treat25 treat10) ///
stats(N r2  rw_pv , fmt(0 3 3 3)  ///
labels(`"Observations"' `"R-squared"' `"Romano-Wolf p-value"' ))

local sample="mv"
esttab est33 est34 est35 est36  est37  est38 est39  est40  est41  est42  est43  est44  est45  est46  est47 est48  using "$output_dir/post_s_extval_`sample'.tex", tex nolines fragment label replace  collabels(none) nomtitles nonumbers star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3)) ) ///
keep(treat25 treat10) ///
stats(N r2  rw_pv , fmt(0 3 3 3)  ///
labels(`"Observations"' `"R-squared"' `"Romano-Wolf p-value"' ))




eststo clear				


			
				
*----------------------------------   end
